/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.service.impl;

import java.util.Collection;
import java.util.List;

import com.xy.biz.fd.domain.converter.DocumentReleaseOftenUseConverter;
import com.xy.biz.fd.domain.req.GetDocumentReleaseOftenUseRequest;
import com.xy.tool.context.UserContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xy.lang.domain.Result;
import com.xy.biz.fd.domain.bo.DocumentReleaseOftenUseBO;
import com.xy.biz.fd.domain.query.DocumentReleaseOftenUseQuery;
import com.xy.biz.fd.service.DocumentReleaseOftenUseService;
import com.xy.biz.fd.manager.DocumentReleaseOftenUseManager;

/**
 *
 *
 * @author zgy
 * @date 2021-6-15
 */
@Service
public class DocumentReleaseOftenUseServiceImpl implements DocumentReleaseOftenUseService {

    @Autowired
    private DocumentReleaseOftenUseManager documentReleaseOftenUseManager;

    @Override
    public Result<?> saveDocumentReleaseOftenUse(DocumentReleaseOftenUseBO documentReleaseOftenUseBO) {
        int affectedRows = documentReleaseOftenUseManager.saveDocumentReleaseOftenUse(documentReleaseOftenUseBO);
        if (affectedRows > 0) {
            return Result.success();
        }
        return Result.ofErrorRowsAffected();
    }

    @Override
    public Result<?> saveAllDocumentReleaseOftenUse(Collection<DocumentReleaseOftenUseBO> collection) {
        int affectedRows = documentReleaseOftenUseManager.saveAllDocumentReleaseOftenUse(collection);
        if (affectedRows > 0) {
            return Result.success();
        }
        return Result.ofErrorRowsAffected();
    }

    @Override
    public Result<?> updateDocumentReleaseOftenUse(DocumentReleaseOftenUseBO documentReleaseOftenUseBO) {
        int affectedRows = documentReleaseOftenUseManager.updateDocumentReleaseOftenUse(documentReleaseOftenUseBO);
        if (affectedRows > 0) {
            return Result.success();
        }
        return Result.ofErrorRowsAffected();
    }

    /**
     * 更新访问量
     *
     * @param request
     */
    @Override
    public Result<?> increment(GetDocumentReleaseOftenUseRequest request) {
        DocumentReleaseOftenUseBO documentReleaseOftenUseBO = DocumentReleaseOftenUseConverter.toBO(request);
        documentReleaseOftenUseBO.setUseUserId(UserContextHolder.getUserId());
        int affectedRows = documentReleaseOftenUseManager.increment(documentReleaseOftenUseBO);
        if (affectedRows > 0) {
            return Result.success();
        }
        return Result.ofErrorRowsAffected();
    }

    @Override
    public Result<?> deleteDocumentReleaseOftenUse(Long documentReleaseOftenUseId) {
        int affectedRows = documentReleaseOftenUseManager.deleteDocumentReleaseOftenUse(documentReleaseOftenUseId);
        if (affectedRows > 0) {
            return Result.success();
        }
        return Result.ofErrorRowsAffected();
    }

    @Override
    public DocumentReleaseOftenUseBO getDocumentReleaseOftenUse(Long documentReleaseOftenUseId) {
        return documentReleaseOftenUseManager.getDocumentReleaseOftenUse(documentReleaseOftenUseId);
    }

    @Override
    public List<DocumentReleaseOftenUseBO> listDocumentReleaseOftenUseById(Collection<Long> collection) {
        return documentReleaseOftenUseManager.listDocumentReleaseOftenUseById(collection);
    }

    @Override
    public List<DocumentReleaseOftenUseBO> listDocumentReleaseOftenUse(DocumentReleaseOftenUseQuery query) {
        return documentReleaseOftenUseManager.listDocumentReleaseOftenUse(query);
    }

    @Override
    public int countDocumentReleaseOftenUse(DocumentReleaseOftenUseQuery query) {
        return documentReleaseOftenUseManager.countDocumentReleaseOftenUse(query);
    }

}
